home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks96
/
FlyPaper.sit
/
Fly Paper
/
FlyPaper Source
/
WDEF
/
NuScrappy.cpp
next >
Wrap
C/C++ Source or Header
|
1996-06-22
|
9KB
|
382 lines
#include <A4Stuff.h>
typedef struct {
WindowPeek theWindow;
short varCode;
CTabPtr colorTable;
} DeviceLoopData;
typedef struct {
Rect r1, r2;
Boolean closeBoxHilited;
} WindowDataRec, **WindowDataHandle;
#define kDragWidth 12
#define kCloseBoxSize 7
#define kCloseBoxYMargin 4
#define kCloseBoxXMargin 2
#define kFrameColor 1
#define kDragBarColor 5
#define kCloseBoxColor 6
#define kDragOnLeftVarCode 1
#define kDragBarVarCode 2
#define kShadowVarCode 4
#define kZigSize 3
CGrafPort gColorPort;
GrafPtr gOldPort;
static
void StartUsingColor ()
{
GetPort (&gOldPort);
OpenCPort (&gColorPort);
CopyRgn (gOldPort -> clipRgn, gColorPort.clipRgn);
CopyRgn (gOldPort -> visRgn, gColorPort.visRgn);
}
static
void StopUsingColor ()
{
CloseCPort (&gColorPort);
SetPort (gOldPort);
}
static
void ZigZag (short varCode, Point start, Point finish)
{
short horizontalOffset = (varCode & kDragOnLeftVarCode) ? -kZigSize : kZigSize;
while (start.v > finish.v) {
LineTo (start.h += horizontalOffset, start.v -= kZigSize);
horizontalOffset *= -1;
}
}
static
void MakeBorder (short varCode, Rect& contentRect, Boolean outset)
{
Point frameStart, frameFinish, zigStart, zigFinish;
short width;
short height, slop;
{
Rect bounds = contentRect;
if (varCode & kDragOnLeftVarCode) {
if (outset) {
frameStart.v = bounds.top - 1;
frameStart.h = bounds.right + 1;
frameFinish.v = bounds.bottom + 1;
frameFinish.h = bounds.right + 1;
width = bounds.left - bounds.right - 2;
zigStart.v = frameFinish.v - 1;
zigStart.h = frameFinish.h;
zigFinish.v = frameStart.v + 1;
zigFinish.h = frameStart.h;
} else {
frameStart.v = bounds.top;
frameStart.h = bounds.right;
frameFinish.v = bounds.bottom;
frameFinish.h = bounds.right;
width = bounds.left - bounds.right;
zigStart = frameFinish;
zigFinish = frameStart;
}
} else {
if (outset) {
frameStart.v = bounds.top - 1;
frameStart.h = bounds.left - 1;
frameFinish.v = bounds.bottom + 1;
frameFinish.h = bounds.left - 1;
width = bounds.right - bounds.left + 2;
zigStart.v = frameFinish.v - 1;
zigStart.h = frameFinish.h;
zigFinish.v = frameStart.v + 1;
zigFinish.h = frameStart.h;
} else {
frameStart.v = bounds.top;
frameStart.h = bounds.left;
frameFinish.v = bounds.bottom;
frameFinish.h = bounds.left;
width = bounds.right - bounds.left;
zigStart = frameFinish;
zigFinish = frameStart;
}
}
}
MoveTo (frameStart.h, frameStart.v);
LineTo (frameStart.h + width, frameStart.v);
LineTo (frameStart.h + width, frameFinish.v);
LineTo (frameFinish.h, frameFinish.v);
LineTo (zigStart.h, zigStart.v);
// calculate slop
height = zigStart.v - zigFinish.v;
slop = height % (kZigSize * 2);
Point actualZigStart = { zigStart.v -= slop / 2, zigStart.h };
Point actualZigFinish = { zigFinish.v + (slop - (slop / 2)), zigFinish.h };
LineTo (actualZigStart.h, actualZigStart.v);
// ZigZag from start to finish
ZigZag (varCode, actualZigStart, actualZigFinish);
LineTo (zigFinish.h, zigFinish.v);
}
static
void CalcDragRect (short varCode, Rect& contentRect, Rect &dragRect)
{
dragRect.top = contentRect.top;
dragRect.left = (varCode & kDragOnLeftVarCode) ? contentRect.left - kDragWidth : contentRect.right;
dragRect.bottom = contentRect.bottom;
dragRect.right = dragRect.left + kDragWidth;
}
static
void CalcCloseRect (short varCode, Rect& contentRect, Rect &closeRect)
{
Rect dragRect;
CalcDragRect (varCode, contentRect, dragRect);
closeRect.top = dragRect.top + kCloseBoxYMargin;
closeRect.left = (varCode & kDragOnLeftVarCode) ? dragRect.left + kCloseBoxXMargin : dragRect.right - kCloseBoxXMargin - kCloseBoxSize;
closeRect.bottom = closeRect.top + kCloseBoxSize;
closeRect.right = closeRect.left + kCloseBoxSize;
}
static
void CalcRgns (short varCode, WindowPeek theWindow)
{
// content rect is in global coordinates
Rect contentRect = theWindow -> port.portRect;
OffsetRect (&contentRect, -theWindow -> port.portBits.bounds.left,
-theWindow -> port.portBits.bounds.top);
// make content rgn
OpenRgn ();
MakeBorder (varCode, contentRect, false);
CloseRgn (theWindow -> contRgn);
// make border of content rgn
OpenRgn ();
MakeBorder (varCode, contentRect, true);
CloseRgn (theWindow -> strucRgn);
Rect dragRect;
CalcDragRect (varCode, contentRect, dragRect);
// add drag rgn to struc rgn
RgnHandle scratchRgn = NewRgn ();
if (varCode & kDragBarVarCode) {
InsetRect (&dragRect, 0, -1);
if (varCode & kDragOnLeftVarCode)
dragRect.left--;
else
dragRect.right++;
RectRgn (scratchRgn, &dragRect);
UnionRgn (theWindow -> strucRgn, scratchRgn, theWindow -> strucRgn);
}
if (varCode & kShadowVarCode) {
// create drop shadow and add to struc rgn
CopyRgn (theWindow -> strucRgn, scratchRgn);
OffsetRgn (scratchRgn, 1, 1);
UnionRgn (theWindow -> strucRgn, scratchRgn, theWindow -> strucRgn);
}
DisposeRgn (scratchRgn);
}
static
void DrawCloseBox (short varCode, WindowPeek theWindow, Boolean invert, CTabPtr colorTable)
{
Rect r;
if (!theWindow -> goAwayFlag)
return;
Rect bbox = (**theWindow -> contRgn).rgnBBox;
CalcCloseRect (varCode, bbox, r);
ForeColor (blackColor);
FrameRect (&r);
InsetRect (&r, 1, 1);
if (invert)
(**((WindowDataHandle) theWindow -> dataHandle)).closeBoxHilited =
!(**((WindowDataHandle) theWindow -> dataHandle)).closeBoxHilited;
if ((**((WindowDataHandle) theWindow -> dataHandle)).closeBoxHilited) {
RGBForeColor (&colorTable -> ctTable [1].rgb);
PaintRect (&r);
} else
EraseRect (&r);
}
static
pascal void myDrawDragBarProc (short depth, short flags, GDHandle device, DeviceLoopData *data)
{
EnterCodeResource ();
Rect r;
Rect temp = (**data -> theWindow -> contRgn).rgnBBox;
CalcDragRect (data -> varCode, temp, r);
RGBForeColor (&data -> colorTable -> ctTable [4].rgb);
PaintRect (&r);
RGBForeColor (&data -> colorTable -> ctTable [1].rgb);
if (data -> varCode & kDragOnLeftVarCode) {
MoveTo (r.right - 1, r.top);
LineTo (r.right - 1, r.bottom);
} else {
MoveTo (r.left, r.top);
LineTo (r.left, r.bottom);
}
DrawCloseBox (data -> varCode, data -> theWindow, false, data -> colorTable);
SetA4 (oldA4);
}
static
void DrawDragBar (short varCode, WindowPeek theWindow, CTabPtr colorTable)
{
DeviceLoopData data;
data.theWindow = theWindow;
data.varCode = varCode;
data.colorTable = colorTable;
DeviceLoop (GetGrayRgn (), (DeviceLoopDrawingUPP) myDrawDragBarProc,
(long) &data, singleDevices);
}
static
void DrawEverything (short varCode, WindowPeek theWindow, CTabPtr colorTable)
{
if (!theWindow -> visible)
return;
RgnHandle r = NewRgn ();
RgnHandle scratch = NewRgn ();
Rect dragRect;
Rect bbox = (**theWindow -> contRgn).rgnBBox;
CalcDragRect (varCode, bbox, dragRect);
RectRgn (scratch, &dragRect);
CopyRgn (theWindow -> strucRgn, r);
DiffRgn (r, scratch, r);
DiffRgn (r, theWindow -> contRgn, r);
// Draw frame
RGBForeColor (&colorTable -> ctTable [1].rgb);
PaintRgn (r);
DrawDragBar (varCode, theWindow, colorTable);
DisposeRgn (r);
DisposeRgn (scratch);
}
static
short DoHit (short varCode, WindowPeek theWindow, Point where)
{
Rect contentRect = (**theWindow -> contRgn).rgnBBox;
if (theWindow -> hilited && theWindow -> goAwayFlag) {
Rect closeRect;
CalcCloseRect (varCode, contentRect, closeRect);
if (PtInRect (where, &closeRect))
return (wInGoAway);
}
Rect dragRect;
CalcDragRect (varCode, contentRect, dragRect);
if (PtInRect (where, &dragRect))
return (wInDrag);
return (wInContent);
}
pascal long main (short varCode, WindowPeek theWindow, short message, long param)
{
EnterCodeResource ();
short retVal;
switch (message) {
case (wDraw) :
AuxWinHandle wctb;
GetAuxWin ((WindowPtr) theWindow, &wctb);
SignedByte state = HGetState ((Handle) (**wctb).awCTable);
HLock ((Handle) (**wctb).awCTable);
StartUsingColor ();
if (param == wInGoAway)
DrawCloseBox (varCode, theWindow, true, *(**wctb).awCTable);
else
DrawEverything (varCode, theWindow, *(**wctb).awCTable);
HSetState ((Handle) (**wctb).awCTable, state);
StopUsingColor ();
break;
case (wHit) :
retVal = DoHit (varCode, theWindow, *((Point*)¶m));
break;
case (wCalcRgns) :
CalcRgns (varCode, theWindow);
break;
case (wNew) :
theWindow -> dataHandle = NewHandleClear (sizeof (WindowDataRec));
break;
case (wDispose) :
DisposeHandle (theWindow -> dataHandle);
break;
default :
return 0;
}
ExitCodeResource ();
return (retVal);
}